package com.wsz.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wsz.pojo.Ucenter;
import com.wsz.ucenter.service.UcenterService;
import com.wsz.ucenter.mapper.UcenterMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author wangs
 * @description 针对表【ucenter】的数据库操作Service实现
 * @createDate 2023-03-12 13:47:50
 */
@Service
public class UcenterServiceImpl extends ServiceImpl<UcenterMapper, Ucenter>
        implements UcenterService {

    @Override
    public Map<String, Object> statisticsByTime(String begin, String end, String type) {
        List<Ucenter> ucenters = this.baseMapper.selectList(
                new LambdaQueryWrapper<Ucenter>()
                        .between(Ucenter::getDate, begin, end)
                        .orderByAsc(Ucenter::getDate));

        List<String> date_list = ucenters.stream().map(Ucenter::getDate).collect(Collectors.toList());
        List<Integer> num_list = new ArrayList<>();

        switch (type) {
            case "register":
                num_list = ucenters.stream().map(Ucenter::getRegisterCount).collect(Collectors.toList());
                break;
            case "record":
                num_list = ucenters.stream().map(Ucenter::getRecordCount).collect(Collectors.toList());
                break;
            case "essays":
                num_list = ucenters.stream().map(Ucenter::getEssaysCount).collect(Collectors.toList());
            default:
                break;
        }
        Map<String, Object> data = new HashMap<>();
        data.put("date_list", date_list);
        data.put("num_list", num_list);
        return data;
    }
}




